﻿#include "StatusBarPropertyEditEntry.h"

#include <QStatusBar>
#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(StatusBar)

#include "BooleanEditEntry.h"

struct StatusBarPropertyEditEntry::StatusBarPropertyEditEntryPrivate {
    QPointer<QStatusBar> object;
    QPointer<BooleanEditEntry> entrySizeGripEnabled;
};

StatusBarPropertyEditEntry::~StatusBarPropertyEditEntry() { }

StatusBarPropertyEditEntry::StatusBarPropertyEditEntry(QWidget *parent) : PropertyEditEntry {parent} {
    p.reset(new StatusBarPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

void StatusBarPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QStatusBar*>(object);
}

void StatusBarPropertyEditEntry::onTick() {
    if(!p->object || !isVisible()) {
        return ;
    }
    p->entrySizeGripEnabled->setValue(p->object->isSizeGripEnabled());
}

void StatusBarPropertyEditEntry::initUi() {
    p->entrySizeGripEnabled = new BooleanEditEntry;
    appendChildEntry(p->entrySizeGripEnabled);
    connect(p->entrySizeGripEnabled.data(), &BooleanEditEntry::valueChanged, [=](bool value) {
        p->object->setSizeGripEnabled(value);
    });
}

void StatusBarPropertyEditEntry::retranslateUi() {
    setTitle(tr("QStatusBar"));
    p->entrySizeGripEnabled->setTitle(tr("sizeGripEnabled"));
}
